﻿@using lsc.Model
@using lsc.crm.ViewModel
@{
    ViewData["Title"] = "工作台";
    Layout = "~/Pages/_Layout.cshtml";
    List<WorkPlan> workplanlist = ViewBag.workplanlist;
    List<EnterCustomer> enterlist = ViewBag.enterlist;
    List<UserReportViewModel> reportlist = ViewBag.reportlist;
    bool isadmin = ViewBag.isadmin;
    int daytotal = 0;
    string day = "距离目标还有4个，加油";
    if (ViewBag.entercustomTotalToday != null)
    {
        daytotal = ViewBag.entercustomTotalToday.Total;
        if(daytotal<=4)
        {
            day = $"距离目标还有{(4 - daytotal).ToString()}个，加油";
        }
        else
        {
            day = $"今天超额完成了{(daytotal - 4).ToString()}！你很棒！";
        }
    }
    string Week = "距离目标还有20个，加油，你很棒";
    int weektotal = 0;
    if (ViewBag.entercustomTotalWeek != null)
    {
        weektotal = ViewBag.entercustomTotalWeek.Total;
        if (weektotal<=20)
        {
            Week = $"距离目标还有{(20 - weektotal)}个，加油，你很棒！";
        }
        else
        {
            Week = $"这周你超额完成了{(weektotal-20)}个，你是最棒的！";
        }
    }
    string Month = "88";
    if (ViewBag.entercustomTotalMonth != null)
    {
        int TotalWeek = ViewBag.entercustomTotalMonth.Total;
        if (TotalWeek<=88)
        {
            Month = (88 - TotalWeek).ToString();
        }
        else
        {
            Month = $"超额完成{(TotalWeek - 88).ToString()}个";
        }
    }
}
<blockquote class="layui-elem-quote">
    工作台
</blockquote>
<div class="layui-fluid">
    @if (!isadmin)
    {
        <div class="layui-row layui-col-space20">
            <div class="layui-col-md4 manage-console-enterreport">
                <div class=" manage-console-enterreport-today">
                    <div class="manage-console-enterreport-title"><span>今日</span></div>
                    <hr class="layui-bg-blue">
                    <div class="layui-col-md6">
                        <p class="manage-console-enterreport-score2">客户数：</p>
                        <p class="manage-console-enterreport-score">@(ViewBag.entercustomTotalToday != null ? ViewBag.entercustomTotalToday.Total : "0")</p>
                        <p class="manage-console-enterreport-score2">@(day) @*&nbsp;&nbsp;&nbsp; 成单数:@ViewBag.projecttotalToday*@</p>
                    </div>
                    <div class="layui-col-md6">
                        <p class="manage-console-enterreport-score2">电话数：</p>
                        <p class="manage-console-enterreport-score">@ViewBag.telphoneToday</p>
                        <p class="manage-console-enterreport-score1">目标：50 </p>
                    </div>
                </div>
            </div>
            <div class="layui-col-md4 manage-console-enterreport">
                <div class="manage-console-enterreport-week">
                    <div class="manage-console-enterreport-title"><span>本周</span></div>
                    <hr class="layui-bg-blue">
                    <div class="layui-col-md6">
                        <p class="manage-console-enterreport-score2">客户数：</p>
                        <p class="manage-console-enterreport-score">@(ViewBag.entercustomTotalWeek != null ? ViewBag.entercustomTotalWeek.Total : "0")</p>
                        <p class="manage-console-enterreport-score2">@(Week) @*&nbsp;&nbsp;&nbsp; 成单数:@ViewBag.projecttotalWeek*@</p>
                    </div>
                    <div class="layui-col-md6">
                        <p class="manage-console-enterreport-score2">电话数：</p>
                        <p class="manage-console-enterreport-score">@ViewBag.telphoneWeek</p>
                        <p class="manage-console-enterreport-score1">目标：250 </p>
                    </div>
                </div>

            </div>
            <div class="layui-col-md4 manage-console-enterreport ">
                <div class="manage-console-enterreport-Month">
                    <div class="manage-console-enterreport-title"><span>本月</span></div>
                    <hr class="layui-bg-blue">
                    <div class="layui-col-md6">
                        <p class="manage-console-enterreport-score2">客户数：</p>
                        <p class="manage-console-enterreport-score">@(ViewBag.entercustomTotalMonth != null ? ViewBag.entercustomTotalMonth.Total : "0")</p>
                        <p class="manage-console-enterreport-score2">目标：@(Month) @*&nbsp;&nbsp;&nbsp; 成单数:@ViewBag.projecttotalMonth*@</p>
                    </div>
                    <div class="layui-col-md6">
                        <p class="manage-console-enterreport-score2">电话数：</p>
                        <p class="manage-console-enterreport-score">@ViewBag.telphoneMonth</p>
                        <p class="manage-console-enterreport-score1">目标：750 </p>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-row layui-col-space20">
            <div class="layui-col-md4 manage-console-enterreport">
                <div class=" manage-console-enterreport-today">
                    <div class="manage-console-enterreport-title"><span>本月应收账款</span></div>
                    <hr class="layui-bg-blue">
                    <p class="manage-console-enterreport-score"><a href="javascript:;" onclick="ReceoverPayOnclick()">@ViewBag.ReceoverPay</a></p>
                </div>
            </div>
            <div class="layui-col-md4 manage-console-enterreport">
                <div class="manage-console-enterreport-week">
                    <div class="manage-console-enterreport-title"><span>本月已收账款</span></div>
                    <hr class="layui-bg-blue">
                    <p class="manage-console-enterreport-score"><a href="javascript:;" onclick="HReceoverPayOnclick()">@ViewBag.HReceoverPay</a></p>
                </div>

            </div>
            <div class="layui-col-md4 manage-console-enterreport ">
                <div class="manage-console-enterreport-Month">
                    <div class="manage-console-enterreport-title"><span>本月到账目标</span></div>
                    <hr class="layui-bg-blue">
                    <p class="manage-console-enterreport-score">@ViewBag.TargetAmt</p>
                </div>
            </div>
        </div>
    }
  
    <!--工作计划-->
    <fieldset class="layui-elem-field layui-field-title">
        <legend>工作计划</legend>
    </fieldset>
    <div class="layui-row">
        <table class="layui-table" lay-skin="line">
            <thead>
                <tr>
                    <th>计划内容</th>
                    <th>客户</th>
                    <th>计划时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                @if (workplanlist != null)
                {
                    foreach (var plan in workplanlist)
                    {
                        string name = string.Empty;
                        if (enterlist!=null)
                        {
                            var enter = enterlist.FirstOrDefault(x => x.ID == plan.EnterCustID);
                            if (enter!=null)
                            {
                                name = enter.EnterName;
                             }
                        }
                        <tr>
                            <td>@plan.PlanContent</td>
                            <td><a href="@(plan.EnterCustID>0 ? "/EnterCustom/EnterCustomInfo?id="+ plan.EnterCustID:"javascript:;")">@name</a></td>
                            <td>@plan.PlanTime.ToString("yyyy-MM-dd")</td>
                            <td>
                                <div class="layui-btn-group">
                                    @if (plan.EnterCustID > 0)
                                    {
                                        <a class="layui-btn layui-btn-small" onclick="showcontroller('@plan.EnterCustID')">查看联系方式</a>
                                        <a class="layui-btn layui-btn-small" onclick="updatephase('@plan.EnterCustID')">添加联系记录</a>
                                        <a class="layui-btn layui-btn-small" onclick="addplan('@plan.EnterCustID')">预约下次</a>
                                    }
                                    <a class="layui-btn layui-btn-small" onclick="finish(@plan.ID)">完成</a>
                                </div>
                            </td>
                        </tr>
                    }
                }
                
            </tbody>
        </table>
    </div>
    <!--昨天工作-->
    @if (isadmin)
    {
        <fieldset class="layui-elem-field layui-field-title">
            <legend>昨天工作</legend>
        </fieldset>
        <div class="layui-row">
            <div class="layui-row" id="content_table">
                <table class="layui-table">
                    <thead>
                        <tr>
                            <th>姓名</th>
                            <th>客户量</th>
                            <th>电话量</th>
                            <th>成单量</th>
                            <th>应收账款</th>
                            <th>回款金额</th>
                        </tr>
                    </thead>
                    <tbody>
                        @if (reportlist != null)
                        {
                            foreach (var info in reportlist)
                            {
                                <tr>
                                    <td>@info.UserName</td>
                                    <td><a href="javascript:;" onclick="custlist('@info.UserID')">@info.CustomorTotal</a></td>
                                    <td><a href="javascript:;" onclick="phoneloglist('@info.UserID')">@info.PhoneTotal</a></td>
                                    <td>@info.SalesProjectTotal</td>
                                    <td>@info.ReceoverPay</td>
                                    <td>@info.HReceoverPay</td>
                                </tr>
                            }
                        }
                    </tbody>
                </table>
            </div>
        </div>
    }
    
</div>


@section Scripts{
    <script type="text/javascript">
        var layer, table
        layui.use(['element', 'layer','table'], function () {
            layer = layui.layer;
            table = layui.table;
        });
        var ReceoverPayOnclick = function () { 
            layer.open({
                type: 2,
                title: '本月应收账款明细',
                shadeClose: true,
                shade: 0.8,
                area: ['1200px', '50%'],
                content: '/EnterCustom/ProjectAmtList'
            });
        }
        var HReceoverPayOnclick = function () { 
            layer.open({
                type: 2,
                title: '本月回款明细',
                shadeClose: true,
                shade: 0.8,
                area: ['900px', '50%'],
                content: '/EnterCustom/ReceovedPayLogList'
            });
        }

        var showcontroller = function (id) {
            layer.open({
                type: 2,
                title: '联系人列表',
                shadeClose: true,
                shade: 0.8,
                area: ['1200px', '70%'],
                content: '/EnterCustom/EnterCustContactsList?EnterCustID=' + id
            });
        }

        updatephase = function (id) {
            layer.open({
                type: 2,
                title: '更新客户所处阶段',
                shadeClose: true,
                shade: 0.8,
                area: ['1200px', '70%'],
                content: '/EnterCustom/AddEnterCustPhaseLog?id=' + id
            });
        }

        finish = function (id) {
            $.get("/EnterCustom/FinishPlan?id=" + id, function (res) {
                window.location.reload();
            })
        }

        addplan = function (id) {
            layer.open({
                type: 2,
                title: '添加工作计划',
                shadeClose: true,
                shade: 0.8,
                area: ['400px', '40%'],
                content: '/EnterCustom/AddWorkPlan?EnterCustID=' + id
            });
        }

        custlist = function (userid) {
            layer.open({
                type: 2,
                title: '客户信息列表',
                shadeClose: true,
                shade: 0.8,
                area: ['1000px', '70%'],
                content: '/EnterCustom/CustomorTotalList?userid=' + userid
            });
        }

        phoneloglist = function (userid) {
            layer.open({
                type: 2,
                title: '电话沟通列表',
                shadeClose: true,
                shade: 0.8,
                area: ['1000px', '70%'],
                content: '/EnterCustom/PhoneTotalList?userid=' + userid
            });
         }
    </script>
}

